var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        passKey:'',
        stationNumber:''
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport
        };
        Api.siteinformation(paramsObj, function(data){
            console.log(data);
            _this.params.stationNumber=data.stationNumber;
        });
    },
    addCard:function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            realName:$('#realName').val(),
            cardNumber:$('#cardNumber').val(),
            mobile:_this.params.stationNumber,
            code:$('#code').val(),
            passKey:_this.params.passKey
        };
        Api.bankcardlistadd(paramsObj, function(data){
            console.log(data);
            layui.use('layer', function(){
                layer.msg('添加成功', {icon: 6});
            });
        });
    },
    getCode:function(mobile){
        var _this = this;
        var paramsObj = {
            mobile:mobile,
            moduleName:'stationapp',
            type:'bank_card '
        };
        Api.sendsms(paramsObj, function(data){
            console.log(data);
            layui.use('layer', function(){
                layer.msg('发送成功', {icon: 6});
            });
            _this.params.passKey=data.passKey;
            $('#getCode').attr('data', '1');
            var count = 60;
            var resend = setInterval(function() {
                count--;
                if (count > 0) {
                    $('#getCode').text('已发送('+count + 's)');
                } else {
                    clearInterval(resend);
                    $('#getCode').attr('data', '0');
                    $('#getCode').text("重新获取");
                }
            }, 1000);
        });
    },
    otherEvent:function(){
        var _this = this;
        $('#getCode').click(function(event) {
            if ($('#mobile').val()) {
                if ($(this).attr('data')==0) {
                    _this.getCode($('#mobile').val());
                };
            }else{
                layui.use('layer', function(){
                    layer.msg('请填写联系方式', {icon: 5});
                });
            };
        });
        $('#addCard').click(function(event) {
            _this.addCard();
        });
        $('#cancel').click(function(event) {
            window.location.href=Pub.getHtmlUrl('./bank-list.html');
        });

    },
    initEvent: function(){
        var _this = this;
        _this.getData();
        _this.otherEvent();


    }
};
var page = new Page();